package com.webguard.outlierdetection.service.impl;


import com.webguard.outlierdetection.mapper.UserMapper;
import com.webguard.outlierdetection.pojo.User;
import com.webguard.outlierdetection.service.UserService;
import com.webguard.outlierdetection.untils.Md5Util;
import com.webguard.outlierdetection.untils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class UserImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String username) {
        return userMapper.findByUserName(username);
    }

    @Override
    public void register(String username, String password,String email) {
        //使用MD5加密
        String encryptPassword = Md5Util.getMD5String(password);
        userMapper.addUser(username,encryptPassword,email);
    }

    @Override
    public void update(User user) {
        user.setUpdateTime(LocalDateTime.now());

        userMapper.update(user);

    }



    @Override
    public void updatePwd(String newPassword, Integer id) {
        userMapper.updatePwd(newPassword,id);

    }

    @Override
    public User findByEmail(String email) {
        return userMapper.findByEmail(email);
    }

    @Override
    public User findById(String id) {
        return userMapper.findById(id);
    }
}
